<?php


/**
 * sfGuardRegister actions.
 *
 * @package    guard
 * @subpackage sfGuardRegister
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z jwage $
 */
class sfGuardRegisterActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    if ($this->getUser()->isAuthenticated())
    {
      $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
      $this->redirect('@homepage');
    }

    $this->form = new RegisterForm();
	$this->topicId = "";
	if($request->getParameter("topicId")) {
	 $this->topicId = $request->getParameter("topicId") ;
	}

    if ($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
      if ($this->form->isValid())
      {
        $user = $this->form->save();
        $this->getUser()->signIn($user);		
		//
		if($request->getParameter("topicId")) {
			$members = new forumMembers();
			//$this->topicId = $request->getParameter("topicId") ;
			$members->setUserId($user->getId());
			$members->setIsActive(false);
			$members->save();
		}

        $this->redirect('@homepage');
      }
    }
  }
}